package com.qp.basics.estivate.support;

import com.qp.basics.estivate.ResultSetExtractor;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 只获取指定字段的值。 注意columnIndex从1开始。
 */
public class SingleColumnResultSetExtractor implements ResultSetExtractor {

	private int columnIndex = 1;

	public SingleColumnResultSetExtractor() {
	}

	public SingleColumnResultSetExtractor(int columnIndex) {
		this.columnIndex = columnIndex;
	}

	public Object extractData(ResultSet resultset) {
		try {
			return resultset.getObject(columnIndex);
		} catch (SQLException e) {
			throw new RuntimeException(e.getMessage(), e);
		}
	}

}
